package com.baseweb.webadmin.controller.web;

import com.baseweb.webadmin.controller.BaseController;
import com.baseweb.webadmin.core.constants.*;
import com.baseweb.webadmin.core.model.bvo.*;
import com.baseweb.webadmin.core.model.pojo.*;
import com.baseweb.webadmin.core.util.*;
import com.baseweb.webadmin.service.ContentService;
import com.baseweb.webadmin.service.RoleService;
import com.baseweb.webadmin.service.UserOrderService;
import com.baseweb.webadmin.service.UserService;
import com.google.gson.Gson;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description: 内容管理控制层
 * @author: xiaoqiang
 * @time: 2017-07-08 11:34
 */
@Controller
@RequestMapping("/htmlWeb")
public class SystemContentController extends BaseController {
    @Autowired
    private RoleService roleService;

    @Autowired
    private ContentService contentService;

    @Autowired
    private UserService userService;

    @Autowired
    private UserOrderService userOrderService;

    /**********栏目模块开始*********/
    @RequestMapping(value = "/program/list")
    @ResponseBody
    public ResultPage<ByChannel> getProgramList(ByChannel channel, RequestPage requestPage) {
        List<ByChannel> list = contentService.selectChannelListByPage1(channel, (requestPage.getCurPage() - 1) * requestPage.getPageSize(), requestPage.getPageSize());
        int total = contentService.selectChannelListCount1(channel);
        ResultPage<ByChannel> resultPage = new ResultPage<>();
        return new ResultPage<ByChannel>(total, requestPage.getPageSize(), list);
    }

    @RequestMapping(value = "/program/getOption")
    @ResponseBody
    public Map<String, Object> getProgramOption(Integer id) {
        Map<String, Object> map = new HashMap<>();
        map.put("adPosition", ChannelPositionType.getTypeOpt());
        ByChannel byChannel = null;
        if (id != null) byChannel = contentService.findChannel(id);
        map.put("channel", byChannel != null ? byChannel : null);
        return map;
    }
    @RequestMapping(value = "/program/getProgram")
    @ResponseBody
    public Map<String, Object> getProgram(Integer id) {
        List<ByChannelKeyword> list = null;
        if (id != null) list = contentService.findChannelKeywordByParentId(id);
        return success(list);
    }
    @RequestMapping(value = "/program/delProgram")
    @ResponseBody
    public Map<String, Object> delProgram(Integer id) {
        if (id != null) contentService.deleteChannel(id);
        return success(null);
    }
    @RequestMapping(value = "/program/save")
    @ResponseBody
    public Map<String, Object> saveProgram(ByChannel channel) {
        if (channel.getId() != null) {//update
            ByChannel old = contentService.findChannel(channel.getId());
            if (old.getLevel() == 1) {
                old.setName(channel.getName());
                old.setSort(channel.getSort());
            } else {
                old.setName(channel.getName());
                old.setDescn(channel.getDescn());
                old.setParentId(channel.getParentId());
                old.setPositionId(channel.getPositionId());
                old.setSort(channel.getSort());
                old.setStatus(channel.getStatus());
                old.setUrl(channel.getUrl());
                old.setLevel(channel.getLevel());
            }
            contentService.insertChannel(old);
            return success(channel.getId());
        } else {//add
            contentService.insertChannel(channel);
            return success(null);
        }
    }
    /**********栏目模块结束*********/
    /**********公告模块开始*********/
    @RequestMapping(value = "/notice/list")
    @ResponseBody
    public ResultPage<ByNotice> getNoticeList(RequestPage requestPage) {
        User user = getCurrentUser();
        user = new User();
        user.setId(null);
        List<ByNotice> list = contentService.selectNoticeListByPage(user.getId(), null,
                (requestPage.getCurPage() - 1) * requestPage.getPageSize(), requestPage.getPageSize());
        int total = contentService.selectNoticeListCount(null, null);
        return new ResultPage<ByNotice>(total, requestPage.getPageSize(), list);
    }

    @RequestMapping(value = "/notice/getOption")
    @ResponseBody
    public Map<String, Object> getNoticeOption(Integer id) {
        Map<String, Object> map = new HashMap<>();
        map.put("noticeType", NoticeType.getAllOpt());
        ByNotice byNotice = null;
        if (id != null) byNotice = contentService.findNotice(id);
        map.put("notice", byNotice != null ? byNotice : null);
        return map;
    }

    @RequestMapping(value = "/notice/save")
    @ResponseBody
    public Map<String, Object> saveNotice(ByNotice byNotice) {
        if (byNotice.getId() != null) {//update
            ByNotice old = contentService.findNotice(byNotice.getId());
            old.setName(byNotice.getName());
            old.setStatus(byNotice.getStatus());
            old.setDescn(byNotice.getDescn());
            old.setNoticeType(byNotice.getNoticeType());
            old.setSort(byNotice.getSort());
            contentService.insertNotice(old);
            return success(byNotice.getId());
        } else {//add
            contentService.insertNotice(byNotice);
            return success(null);
        }
    }
    /**********公告模块结束*********/

    /**********广告模块开始*********/
    @RequestMapping(value = "/adv/list")
    @ResponseBody
    public ResultPage<ByAd> getAdvList(ByAd byAd, RequestPage requestPage) {
        User user = getCurrentUser();
        byAd.setIsCheck(null);
        if (byAd != null) {
            if (byAd.getProvince() != null && (byAd.getProvince().equals("省份") || byAd.getProvince().equals(""))) {
                byAd.setProvince(null);
            }
            if (byAd.getCity() != null && (byAd.getCity().equals("城市") || byAd.getCity().equals(""))) {
                byAd.setCity(null);
            }
            if (byAd.getDistrict() != null && (byAd.getDistrict().equals("区域") || byAd.getDistrict().equals(""))) {
                byAd.setDistrict(null);
            }
        }
        List<ByAd> list = contentService.selectAdListByPage1(byAd,
                (requestPage.getCurPage() - 1) * requestPage.getPageSize(), requestPage.getPageSize());
        int total = contentService.selectAdListCount1(byAd);
        return new ResultPage<ByAd>(total, requestPage.getPageSize(), list);
    }
    @RequestMapping(value = "/adv/getAdv")
    @ResponseBody
    public Map<String, Object> getAdv(Integer id) {
        List<ByAd> list = null;
        if (id != null) list = contentService.findAllByParentId(id);
        return success(list);
    }
    @RequestMapping(value = "/adv/delAdv")
    @ResponseBody
    public Map<String, Object> delAdv(Integer id) {
        if (id != null) contentService.deleteAd(id);
        return success("删除成功");
    }
    @RequestMapping(value = "/adv/loadAdvThreeData",method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> loadAdvThreeData(Integer parentId, Integer advType, String city) {
        List<ByAd> list = new ArrayList<>();
        if(advType!=null&&(advType == 1 || advType == 2 || advType == 3)){
            list = contentService.findAllByParentId(parentId, 1000, "");
        }else {
            list = contentService.findAllByParentId(parentId, 1000, city==null?"":city);
        }
        return success(list,"查询成功");
    }
    /**
     * @description：新增，编辑界面初始化数据获取
     * @author: xiaoqiang
     * @param: [id: 主键，advType: 1广告2广告栏目]
     * @return:
     */
    @RequestMapping(value = "/adv/getOption",produces = "text/json; charset=UTF-8")
    @ResponseBody
    public String getAdvOption(Integer id, Integer parentId, Integer advType, Integer userId) {
        Map<String, Object> map = new HashMap<>();
        ByAd ad = new ByAd();
        if (advType == 3) {
            if (id != null) {
                ad = contentService.findAd(id);
                if (ad != null && ad.getEntityId() != null) {
                    User user = userService.selectUserById(ad.getEntityId());
                    if (user != null)
                        ad.setMobile(user.getUsername());
                }
                if (ad.getUrl().equals("case_ListHtml")) {
                    ad.setUrlStatus(1);
                } else {
                    ad.setUrlStatus(-1);
                }
            }
        } else if (advType == 2) {
            if (id != null) {
                ad = contentService.findAd(id);
                if (ad != null && ad.getEntityId() != null) {
                    User user = userService.selectUserById(ad.getEntityId());
                    if (user != null)
                        ad.setMobile(user.getUsername());
                }
                if (ad.getUrl().equals("case_ListHtml")) {
                    ad.setUrlStatus(1);
                } else {
                    ad.setUrlStatus(-1);
                }
            } else {
                ad.setParentId(parentId);
                ad.setParentName(parentId.toString());
            }
        }
        if(userId !=null) {
            List<ByOpenCity> byOpenCityList = userService.findAllCityByUserId(userId);
            map.put("byOpenCityList", byOpenCityList);
        }
        if(ad != null){
            ad.setCreateTime(null);
            ad.setUpdateTime(null);
        }
        map.put("adv", ad != null ? ad : null);
        Gson gson = new Gson();
        String result = gson.toJson(map);
        return result;
    }

    @RequestMapping(value = "/adv/save")
    @ResponseBody
    public Map<String, Object> saveAdv(ByAd adv,
                                       @RequestParam(value = "file", required = false) MultipartFile file) {
        String img_url = "";
        if (file != null && file.getSize() > 0) {
            img_url = MD5Util.Md5(System.currentTimeMillis() + RandCharUtil.getRandStr(8)
                    + MD5Util.Md5(file.getOriginalFilename())) + ".jpg";
            try {
                UploadUtil.uploadData(file.getBytes(), img_url);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (adv.getId() != null) {//update
            ByAd old = contentService.findAd(adv.getId());
            old.setName(adv.getName());
            old.setStatus(adv.getStatus());
            old.setSort(adv.getSort());
            old.setParentId(adv.getParentId());
            if (!"".equals(img_url))
                old.setImgUrl(img_url);
            User user = null;
            if (adv != null)
                user = userService.selectByUserName(adv.getMobile());
            if (user != null)
                old.setEntityId(user.getId());
            else {
                old.setEntityId(null);
                old.setMobile("");
            }

            if (adv.getUrlStatus() == 1)
                adv.setUrl("case_ListHtml");
            else
                adv.setUrl("#");
            old.setUrl(adv.getUrl());
            old.setDescn(adv.getDescn());
            old.setProvince(adv.getProvince());
            old.setCity(adv.getCity());
            old.setDistrict(adv.getDistrict());
            old.setUpdateTime(new DateTime());
            contentService.insertAd(old);
            return success(old.getId());
        } else {//add
            if (!"".equals(img_url))
                adv.setImgUrl(img_url);
            User user = null;
            if (adv != null)
                user = userService.selectByUserName(adv.getMobile());
            if (user != null)
                adv.setEntityId(user.getId());
            if (adv.getUrlStatus() == 1)
                adv.setUrl("case_ListHtml");
            else
                adv.setUrl("#");
            adv.setPositionId(adv.getParentId());
            contentService.insertAd(adv);
            return success("保存成功");
        }
    }

    @RequestMapping(value = "/adv/setIsChecked")
    @ResponseBody
    public Map<String, Object> setIsChecked(Integer id, Integer isCheck) {
        if (id != null) {
            ByAd old = contentService.findAd(id);
            old.setIsCheck(isCheck);
            contentService.insertAd(old);
        }
        return success(null);
    }
    /**********广告模块结束*********/

    /**********用户反馈模块开始*********/
    @RequestMapping(value = "/feedback/list")
    @ResponseBody
    public ResultPage<ByUserFeedback> getFeedbackList(ByUserFeedback feedback, RequestPage requestPage) {
        User user = getCurrentUser();
        user = new User();
        user.setId(null);
        List<ByUserFeedback> list = contentService.selectFeedbackListByPage1(feedback,
                (requestPage.getCurPage() - 1) * requestPage.getPageSize(), requestPage.getPageSize());
        int total = contentService.selectFeedbackListCount1(feedback);
        return new ResultPage<ByUserFeedback>(total, requestPage.getPageSize(), list);
    }

    @RequestMapping(value = "/feedback/getOption")
    @ResponseBody
    public Map<String, Object> getFeedbackOption(Integer id) {
        Map<String, Object> map = new HashMap<>();
        map.put("status", FeedBackDealType.getTypeOpt());
        return map;
    }

    @RequestMapping(value = "/feedback/save")
    @ResponseBody
    public Map<String, Object> saveFeedback(ByUserFeedback feedback) {
        ByUserFeedback feedback1 = contentService.findFeedback(feedback.getId());
        feedback1.setStatus(1);
        contentService.insertFeedback(feedback1);
        return success(null);
    }
    /**********用户反馈模块结束*********/

    /**********文章模块开始*********/
    @RequestMapping(value = "/article/list")
    @ResponseBody
    public ResultPage<ByArticle> getArticleList(RequestPage requestPage) {
        User user = getCurrentUser();
        user = new User();
        user.setId(null);
        List<ByArticle> list = contentService.selectArticleListByPage(user.getId(), null, null,
                (requestPage.getCurPage() - 1) * requestPage.getPageSize(), requestPage.getPageSize());
        int total = contentService.selectArticleListCount(null, null, null);
        return new ResultPage<ByArticle>(total, requestPage.getPageSize(), list);
    }

    @RequestMapping(value = "/article/getOption")
    @ResponseBody
    public Map<String, Object> getArticleOption(Integer id) {
        Map<String, Object> map = new HashMap<>();
        map.put("articleType", ArticleType.getTypeOpt());
        map.put("artPosition", ArticlePositionType.getTypeOpt());
        ByArticle byArticle = null;
        if (id != null) byArticle = contentService.findArticle(id);
        map.put("article", byArticle != null ? byArticle : null);
        return map;
    }

    @RequestMapping(value = "/article/save")
    @ResponseBody
    public Map<String, Object> saveArticle(ByArticle article) {
        if (article.getId() != null) {//update
            ByArticle old = contentService.findArticle(article.getId());
            old.setName(article.getName());
            old.setStatus(article.getStatus());
            old.setDescn(article.getDescn());
            old.setArticleType(article.getArticleType());
            old.setPositionId(article.getPositionId());
            contentService.insertArticle(old);
            return success(article.getId());
        } else {//add
            contentService.insertArticle(article);
            return success(null);
        }
    }
    /**********文章模块结束*********/
    /**********关键字模块开始*********/
    @RequestMapping(value = "/keyword/list")
    @ResponseBody
    public ResultPage<ByChannelKeyWordBvo> getKeywordList(
            @RequestParam(value = "status", required = false) Integer status,
            @RequestParam(value = "name", required = false) String name,
            @RequestParam(value = "position_id", required = false) Integer position_id,
            @RequestParam(value = "parent_id", required = false) Integer parent_id,
            RequestPage requestPage) {
        User user = getCurrentUser();

        List<ByChannelKeyWordBvo> list = new ArrayList<ByChannelKeyWordBvo>();
        List<ByChannelKeyword> byChannelKeywords = contentService.selectKeyWordListByPage(position_id, parent_id, name, status,
                (requestPage.getCurPage() - 1) * requestPage.getPageSize(), requestPage.getPageSize());

        if (byChannelKeywords != null && byChannelKeywords.size() > 0) {
            for (ByChannelKeyword current : byChannelKeywords) {
                ByChannelKeyWordBvo byChannelKeyWordBvo = ByChannelKeyWordBvo.copyFrom(current, contentService.findChannel(current.getParentId()));
                list.add(byChannelKeyWordBvo);
            }
        }
        long total = contentService.selectKeyWordListCount(position_id, parent_id, name, status);
        return new ResultPage<ByChannelKeyWordBvo>(total, requestPage.getPageSize(), list);
    }
    @RequestMapping(value = "/keyword/delKeyword")
    @ResponseBody
    public Map<String, Object> delKeyword(Integer id) {
        if (id != null) contentService.deleteChannelKeyWord(id);
        return success(null);
    }
    @RequestMapping(value = "/keyword/allList")
    @ResponseBody
    public List<ByChannelKeyword> selectKeyWordAllList() {
        List<ByChannelKeyword> byChannelKeywords = contentService.selectKeyWordAllList();
        return byChannelKeywords;
    }

    @RequestMapping(value = "/keyword/getOption")
    @ResponseBody
    public Map<String, Object> getKeywordOption(Integer id) {
        Map<String, Object> map = new HashMap<>();
        ByAd ad = new ByAd();
        map.put("parentId", contentService.selectChannelListLevel2());
        ByChannelKeyword keyword = null;
        if (id != null) keyword = contentService.findKeyWord(id);
        map.put("keyword", keyword != null ? keyword : null);
        map.put("status", IsEnableType.getTypeOpt());
        return map;
    }

    @RequestMapping(value = "/keyword/save")
    @ResponseBody
    public Map<String, Object> saveKeyword(ByChannelKeyword keyword) {
        if (keyword.getId() != null) {//update
            ByChannelKeyword old = contentService.findKeyWord(keyword.getId());
            old.setName(keyword.getName());
            old.setStatus(keyword.getStatus());
            old.setDescn(keyword.getDescn());
            old.setSort(keyword.getSort());
            old.setParentId(keyword.getParentId());
            contentService.insertKeyWord(old);
            return success(keyword.getId());
        } else {//add
            contentService.insertKeyWord(keyword);
            return success(null);
        }
    }
    /**********关键字模块结束*********/
    /**********意向客户模块开始*********/
    @RequestMapping(value = "/custom/list")
    @ResponseBody
    public ResultPage<ByUserWedBudget> getIntentCustomList(HttpServletRequest request,ByUserWedBudget custom, RequestPage requestPage) {
        String userType = String.valueOf(request.getSession().getAttribute("login_type"));
        List<String> areaList = null;
        if(!(UserType.SUPER_ADMIN.getCode() + "").equals(userType)){
            Object temp = request.getSession().getAttribute("login_id");
            Integer userId = temp == null ? 0 : Integer.valueOf(temp.toString());
            List<ByOpenCity> byOpenCityList = userService.findAllAreaByUserId(userId);
            areaList = new ArrayList<>();
            for(ByOpenCity city : byOpenCityList){
                areaList.add(city.getArea());
            }
            custom.setDistrictList(areaList);
        }

        List<ByUserWedBudget> list = userService.selectIntentCustomListByPage(custom,
                (requestPage.getCurPage() - 1) * requestPage.getPageSize(), requestPage.getPageSize());

        long total = userService.selectIntentCustomListCount(custom);
        return new ResultPage<ByUserWedBudget>(total, requestPage.getPageSize(), list);
    }

    @RequestMapping(value = "/custom/getOption")
    @ResponseBody
    public Map<String, Object> getIntentCustomOption(Integer id) {
        return null;
    }

    @RequestMapping(value = "/intentCustom/save")
    @ResponseBody
    public Map<String, Object> saveIntentCustom(ByUserWedBudget custom) {
        if (custom.getId() != null) {//update
            ByUserWedBudget old = userService.findBudget(custom.getId());
            old.setContact(custom.getContact());
            old.setStatus(custom.getStatus());
            old.setDescn(custom.getDescn());
            old.setMobile(custom.getMobile());
            old.setProvince(custom.getProvince());
            old.setCity(custom.getCity());
            old.setDistrict(custom.getDistrict());
            userService.insertBudget(custom);
            return success(custom.getId());
        } else {//add
            userService.insertBudget(custom);
            return success(null);
        }
    }
    /**********意向客户块结束*********/
    /**********评论管理块开始*********/
    /**
     * @description：
     * @author: xiaoqiang
     * @param: type:1评论列表，2我的评论
     * @return:
     */
    @RequestMapping(value = "/evaluation/list")
    @ResponseBody
    public ResultPage<ByUserOrderEvaluatvo> getCommentList(ByUserOrder userOrder, Integer type, RequestPage requestPage) {
        userOrder.setStatus(OrderStatus.CONFIRM_ORDER.getCode());
        List<ByUserOrderEvaluatvo> commentList = userOrderService.selectOrderListByBizUserOfEvaluation(userOrder, (requestPage.getCurPage() - 1) * requestPage.getPageSize(), requestPage.getPageSize());
        userOrder.setFindFlag(2);
        int total = userOrderService.selectOrderListByBizUserCountzOfEvalution(userOrder);
        return new ResultPage<ByUserOrderEvaluatvo>(total, requestPage.getPageSize(), commentList);
    }
    /**********评论管理块结束*********/
    /**
     * 新增意向客户的数据
     *
     * @param vcode  验证码
     * @param custom 意向客户实体
     * @param model  模型
     * @return
     */
    @RequestMapping(value = "/valid_code")
    public String saveIntentCustom(HttpServletRequest request, @RequestParam(value = "vcode") String vcode,
                                   ByUserWedBudget custom, Model model) {
        /**
         * 手机号码和发送的手机验证码一致性验证
         */
        String result = CheckCodeUtil.verify(custom.getMobile(), vcode);
        if ("1".equals(result)) {
            Object province = request.getSession().getAttribute("login_province");
            Object city = request.getSession().getAttribute("login_city");
            Object area = request.getSession().getAttribute("login_area");
            DateTime dtime = new DateTime();
            custom.setCreateTime(dtime);
            custom.setUpdateTime(dtime);
            custom.setCity(city == null ? "" : city.toString());
            custom.setProvince(province == null ? "" : province.toString());
            custom.setDistrict(area == null ? "" : area.toString());
            userService.insertBudget(custom);
            model.addAttribute("retMsg", "成功");
        } else {
            model.addAttribute("retMsg", "验证码错误！");
        }
        return "";
    }

    /**********认证模块开始*********/
    @RequestMapping(value = "/certiAudit/list")
    @ResponseBody
    public ResultPage<ByUserBizAuthvo> getAuthList(ByUserBizAuthvo auth, RequestPage requestPage) {
        List<ByUserBizAuthvo> list = userService.selectBizVerifyListByPage1(auth, (requestPage.getCurPage() - 1) * requestPage.getPageSize(), requestPage.getPageSize());
        auth.setFindFlag(2);
        int total = userService.selectBizVerifyListCount1(auth);
        return new ResultPage<ByUserBizAuthvo>(total, requestPage.getPageSize(), list);
    }

    /**
     * 通过userId获取认证信息
     * @param userId
     * @return
     */
    @RequestMapping(value = "/certiAudit/getAuth")
    @ResponseBody
    public ByUserBizAuthvo getAuth(Integer userId) {
        ByUserBizAuthvo auth = new ByUserBizAuthvo();
        auth.setStatus(1);
        auth.setFindFlag(1);
        List<ByUserBizAuthvo> list = userService.selectBizVerifyListByPage1(auth, 0,10);
        if(list!=null&& list.size()>0){
            return list.get(0);
        }
        return null;
    }

    /**
     * @param userId   商家ID
     * @param roleType 认证用户角色：3个人商家，4团队商家
     * @return
     */
    @RequestMapping(value = "/certiAudit/getOption")
    @ResponseBody
    public Map<String, Object> getCertiAuditOption(Integer userId, String roleType) {
        Map<String, Object> map = new HashMap<>();
        List<ByUserBizAuth> list = userService.findUserBizAuthByUserId(userId);
        List<ByUserBizAuth> list2 = userService.selectBizVerifyStatusList1(userId);
        ByUserBizAuth auth = null;
        map.put("authList", list);
        map.put("authVerifyBvo", list2);
        map.put("auth", auth != null ? auth : null);
        map.put("authType", AuthType.getRestOpt(list));
        map.put("certificatesType", CertificatesType.getTypeOpt());
        if (roleType != null) {
            if (Integer.valueOf(roleType) == 3)
                map.put("authLevel", AuthLevel.getPersonTypeOpt());
            else
                map.put("authLevel", AuthLevel.getTeamTypeOpt());
        }
        return map;
    }

    @RequestMapping(value = "/certiAudit/getSearchOption")
    @ResponseBody
    public Map<String, Object> getCertiAuditOptionSearch(Integer userId, String roleType) {
        Map<String, Object> map = new HashMap<>();
        map.put("authType", AuthType.getTypeOpt());
        map.put("certificatesType", CertificatesType.getTypeOpt());
        map.put("authStatus", VerifyStatus.getTypeOpt());
        return map;
    }

    @RequestMapping(value = "/certiAudit/save")
    @ResponseBody
    public Map<String, Object> saveCertiAudit(ByUserBizAuth auth, @RequestParam(value = "file", required = false) MultipartFile file) {
        String img_url = "";
        if (file != null && file.getSize() > 0) {
            img_url = MD5Util.Md5(System.currentTimeMillis() + RandCharUtil.getRandStr(8)
                    + MD5Util.Md5(file.getOriginalFilename())) + ".jpg";
            try {
                UploadUtil.uploadData(file.getBytes(), img_url);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (auth.getId() != null) {//update
            ByUserBizAuth old = userService.findBizVerify(auth.getId());
            /*
            return success(old.getId());*/
            return null;
        } else {//add
            if (!"".equals(img_url))
                auth.setImgUrl(img_url);
            boolean f = false;
            ByUserBizAuth au = null;
            List<ByUserBizAuth> olds = userService.findUserBizAuthByUserId(auth.getUserId());
            if (olds != null && olds.size() > 0) {
                for (int i = 0; i < olds.size(); i++) {
                    ByUserBizAuth a = olds.get(i);
                    if (a.getAuthType() == 3 && auth.getAuthType() == 3) {
                        f = true;
                        au = a;
                        break;
                    }
                }
            }
            if (f) {
                au.setName(auth.getName());
                au.setUpdateTime(new DateTime());
                au.setStatus(-1);
                au.setDescn(auth.getDescn());
                au.setAuthLevel(auth.getAuthLevel());
                au.setImgUrl(auth.getImgUrl());
                au.setCertificatesType(auth.getCertificatesType());
                userService.insertBizVerify(au);
            } else {
                userService.insertBizVerify(auth);
            }
            return success(null);
        }
    }

    @RequestMapping(value = "/certiAudit/certiAuditData")
    @ResponseBody
    public Map<String, Object> certiAuditData(ByUserBizAuthvo auth) {
        ByUserBizAuth old = userService.findBizVerify(auth.getId());
        if (old != null) {
            old.setStatus(auth.getStatus());
            old.setUpdateTime(new DateTime());
            userService.insertBizVerify(old);
        }
        return success(null);
    }
    /**********认证模块结束*********/

    /**********广告审核模块开始*********/
    @RequestMapping(value = "/advAudit/list")
    @ResponseBody
    public ResultPage<ByAd> advAudit(ByAd byAd, RequestPage requestPage) {
        User user = getCurrentUser();
        byAd.setParentId(null);
        if (byAd != null) {
            if (byAd.getProvince() != null && byAd.getProvince().equals("省份")) {
                byAd.setProvince(null);
            }
            if (byAd.getCity() != null && byAd.getCity().equals("城市")) {
                byAd.setCity(null);
            }
            if (byAd.getDistrict() != null && byAd.getDistrict().equals("区域")) {
                byAd.setDistrict(null);
            }
        }
        List<ByAd> list = contentService.selectAdListByPage1(byAd,
                (requestPage.getCurPage() - 1) * requestPage.getPageSize(), requestPage.getPageSize());
        int total = contentService.selectAdListCount1(byAd);
        return new ResultPage<ByAd>(total, requestPage.getPageSize(), list);
    }
    /**********广告审核模块接收*********/
}
